package com.heima.media.controller;

import com.heima.common.dto.ResponseResult;
import com.heima.media.dto.ChannelDto;
import com.heima.media.entity.WmChannel;
import com.heima.media.service.IWmChannelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author WSJ
 * @Date 2022-03-09-14:56
 * @Version 1.0 （版本号）
 */
@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理API")
public class WmChannelController {

    @Autowired
    private IWmChannelService wmChannelService;

    /**
     * 根据名称模糊查询频道分页列表
     * @param dto
     * @return
     */
    @ApiOperation(value = "根据名称模糊查询频道分页列表",notes = "author：WSJ")
    @ApiImplicitParam(name = "dto",value = "查询对象",required = true,dataType = "ChannelDto")
    @PostMapping("/list")
    public ResponseResult listByName(@RequestBody ChannelDto dto) {
        return wmChannelService.listByName(dto);
    }

    /**
     * 频道新增
     * @param channel
     * @return
     */
    @PostMapping
    @ApiOperation(value = "频道新增",notes = "author：WSJ")
    @ApiImplicitParam(name = "channel",value = "新增频道信息",required = true,dataType = "WmChannel")
    public ResponseResult saveChannel(@RequestBody WmChannel channel){
        return wmChannelService.saveChannel(channel);
    }

    /**
     * 频道列表
     * @return
     */
    @ApiOperation(value = "频道列表",notes = "author：WSJ")
    @GetMapping("/channels")
    public ResponseResult list() {
        return wmChannelService.listByStatus();
    }

    /**
     * 修改频道信息
     * @param entity
     * @return
     */
    @PutMapping
    public ResponseResult updateChannel(@RequestBody WmChannel entity) {
        return wmChannelService.updateChannel(entity);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    public ResponseResult deleteById(@PathVariable("id") Integer id) {
        return wmChannelService.deleteById(id);
    }

}
